package com.lxl.view;

import java.awt.BorderLayout;
import java.awt.EventQueue;

import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;
import javax.swing.JOptionPane;
import javax.swing.JTextField;
import javax.swing.JLabel;
import javax.swing.JButton;

import com.lxl.service.BookClassifyService;
import com.lxl.service.impl.BookClassifyServiceImpl;

import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.awt.Font;
import java.awt.Cursor;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;

/**
 * @author 刘星鹭
 * @Email liuxinglumail@163.com
 * @version 创建时间： 2014年9月12日 下午3:22:11
 */

public class DeleteBookClassify extends JFrame {

	private static final long serialVersionUID = 1L;
	private JPanel contentPane;
	private JTextField bookclassname;

	public static void main(String[] args) {
		EventQueue.invokeLater(new Runnable() {
			public void run() {
				try {
					DeleteBookClassify frame = new DeleteBookClassify();
					frame.setVisible(true);
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
		});
	}

	public DeleteBookClassify() {
		addWindowListener(new WindowAdapter() {
			@Override
			public void windowClosing(WindowEvent arg0) {

				ViewBookClassify.main(new String[1]);

			}
		});
		setFont(new Font("微软雅黑", Font.PLAIN, 12));
		setTitle("图书管理系统");
		setBounds(100, 100, 450, 180);
		contentPane = new JPanel();
		contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
		contentPane.setLayout(new BorderLayout(0, 0));
		setContentPane(contentPane);

		JPanel panel = new JPanel();
		contentPane.add(panel, BorderLayout.CENTER);
		panel.setLayout(null);

		bookclassname = new JTextField();
		bookclassname.setFont(new Font("微软雅黑", Font.PLAIN, 12));
		bookclassname.setBounds(158, 31, 239, 32);
		panel.add(bookclassname);
		bookclassname.setColumns(10);

		JLabel label = new JLabel("请输入欲删除的类型名：");
		label.setFont(new Font("微软雅黑", Font.PLAIN, 12));
		label.setBounds(26, 39, 138, 15);
		panel.add(label);

		JButton btnNewButton = new JButton("删除");
		btnNewButton.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
		btnNewButton.setFont(new Font("微软雅黑", Font.PLAIN, 12));
		btnNewButton.addMouseListener(new MouseAdapter() {
			@Override
			public void mouseClicked(MouseEvent arg0) {
				String name = bookclassname.getText();
				if (name.equals(""))
					JOptionPane.showMessageDialog(null, "请填写类型名！");
				else {
					BookClassifyService bookClassifyService = new BookClassifyServiceImpl();
					bookClassifyService.delete(name);
					JOptionPane.showMessageDialog(null, "删除成功！");
				}
			}
		});
		btnNewButton.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
			}
		});
		btnNewButton.setBounds(159, 87, 93, 23);
		panel.add(btnNewButton);
	}
}
